import os
from typing import Optional

class Settings:
    # Browser settings
    USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
    HEADLESS = True
    USER_DATA_DIR = os.getenv("USER_DATA_DIR", "data")
    
    # File paths
    CSV_STORE_PATH = "data/BQG.csv"
    
    # URLs
    # BASE_URL = "https://m.30626a.sbs/"
    BASE_URL = "https://m.30626a.sbs/"
    MAP_URL = f"{BASE_URL}map/"
    
    # Concurrency settings
    MAX_CONCURRENT_PAGES = 50

    MONGODB_HOST = os.getenv("MONGODB_HOST", "127.0.0.1")
    MONGODB_PORT = int(os.getenv("MONGODB_PORT", 27017))
    MONGO_CONNECTION_STRING=f"mongodb://user:pass@{MONGODB_HOST}:{MONGODB_PORT}"

    DB_HOST = os.getenv("DB_HOST", "127.0.0.1")
    DB_PORT = int(os.getenv("DB_PORT", 3306))
    DB_USER = os.getenv("DB_USER", "user")
    DB_PASSWORD = os.getenv("DB_PASSWORD", "pass")
    DB_NAME = os.getenv("DB_NAME", "bqg_spider")

    NOVELS = False
    NOVEL = "步步登阶"
    @property
    def DATABASE_URL(self) -> str:
        """动态构建 SQLAlchemy 数据库连接字符串"""
        return f"mysql+mysqlconnector://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"